package com.yao.cofig;

import com.yao.interceptor.UserInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration  //定义此类为配置类（相当于以前的xml配置）
public class InterceptorConfig implements WebMvcConfigurer {


    //mvc:interceptors
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截user下的所有请求，必须用户登录才可以访问
        String[] addPathPatterns = {
                "/user/**"
        };
        //排除user下某些不需要登录就可以访问的
        String[] excludePathPatterns = {
                "/user/out","/user/myError","/user/login"
        };

        //mvc:interceptor
        registry.addInterceptor(new UserInterceptor()).
                addPathPatterns(addPathPatterns).excludePathPatterns(excludePathPatterns);
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
